home *** CD-ROM | disk | FTP | other *** search
/ EuroCD 3 / EuroCD 3.iso / Games / AGA / Shoot / Source / shootconv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-24  |  16.7 KB  |  810 lines

  1. /* Copyright 1990 by Christopher A. Wichura.
  2.    See file GIFMachine.doc for full description of rights.
  3. */
  4.  
  5. #include <exec/types.h>
  6. #include <exec/lists.h>
  7. #include <exec/nodes.h>
  8. #include <string.h>
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. #include <exec/memory.h>
  12. #include <libraries/dos.h>
  13. #include <graphics/rastport.h>
  14. #include <graphics/gfxbase.h>
  15. #include <graphics/gfx.h>
  16. #include <intuition/intuition.h>
  17.  
  18. extern void ReadCodex(void);
  19. extern void getgif(void);
  20.  
  21. /* Nur fuer shoot */
  22. #include "shoot.h"
  23. extern int numtiles;
  24. extern UBYTE tiles[ TILESMAX ][ DEPTH ][ TILESHEIGHT ][ TILESWIDTH ];
  25.  
  26. void beak( char * );
  27.  
  28. int images;
  29. USHORT picinfowidth;
  30. USHORT picinfoheight;
  31. UBYTE ByteBuf;
  32. USHORT pimx, pimy;
  33. APTR pimdata;
  34. USHORT pimstart, pimlines;
  35. USHORT hires;
  36.  
  37. struct MyMem {
  38.     struct MinNode mm_Node;
  39.     ULONG mm_Size;
  40. };
  41.  
  42. /* some structures to make parsing the gif files a bit easier */
  43. struct GIFdescriptor {
  44.     UWORD gd_Width;
  45.     UWORD gd_Height;
  46.     UBYTE gd_ColInfo;
  47.     UBYTE gd_BackGround;
  48.     UBYTE gd_PixelAspect;    /* Aspect Ratio = (Pixel Aspect + 15) / 64 */
  49. };
  50.  
  51. struct ImageDesc {
  52.     UWORD id_Left;
  53.     UWORD id_Top;
  54.     UWORD id_Width;
  55.     UWORD id_Height;
  56.     UBYTE id_Info;
  57. };
  58.  
  59. struct RGB {
  60.     UBYTE rgb_Red;
  61.     UBYTE rgb_Green;
  62.     UBYTE rgb_Blue;
  63. };
  64.  
  65. #define GIF_IMAGE      0x2C
  66. #define GIF_EXTENSION  0x21
  67. #define GIF_TERMINATOR 0x3B
  68.  
  69. #define GIF_COMMENT_EXT 0xFE
  70.  
  71. #define MAXCOLOURS 4096
  72.  
  73. /* these next macros are used to get the r, g, and b values of a given
  74.    index */
  75. #define GetRed(a)    (UBYTE)(a >> 8)
  76. #define GetGreen(a)    (UBYTE)((a >> 4) & 0xF)
  77. #define GetBlue(a)    (UBYTE)(a & 0xF)
  78.  
  79. /* whenever we want to abort we will return this as our error code */
  80. #define ABORTEXITVAL 1
  81.  
  82. /* this struct is used to hold the linked list of comments found in the GIF
  83.    file so that each can be written as a seperate ANNO chunk. */
  84. struct CommentNode {
  85.     struct MinNode cn_Node;
  86.     char *cn_Comment;
  87.     ULONG cn_CommentLength;
  88. };
  89.  
  90. /* function prototypes we use */
  91. void    WarnMustUseCLI(void);
  92. void    DoPattern(char *);
  93. void    Convert(UWORD, UWORD, char *);
  94. BOOL    IsDir(char *);
  95. void    FlipWord(UWORD *);
  96. BOOL    DoImage(APTR);
  97. BOOL    DoExtension(APTR);
  98. BOOL    WriteIFF(char *, BOOL);
  99. void    PutValue(UWORD, UWORD, UWORD);
  100. UWORD    GetValue(UWORD, UWORD);
  101. int    ReadCode(APTR);
  102. void    AddPixel(UBYTE);
  103. void    StripBorder(void);
  104. BOOL    BorderCheck(UWORD, UWORD);
  105. void    DoXComp(void);
  106. void    GIFtoSHAM(void);
  107. void    InitDiff(void);
  108. ULONG    RGBdiff(UBYTE, UBYTE, UBYTE, UBYTE, UBYTE, UBYTE);
  109. void    OutDump(int);
  110. void    OutRun(int, int);
  111. void    InitMemory(void);
  112. char *    MyAlloc(ULONG);
  113. void    MyFree(char *);
  114. void    FreeAll(UWORD);
  115. void    MyExit(ULONG);
  116. void    DoXFlip(void);
  117. void    DoYFlip(void);
  118. void    ReduceTo12(void);
  119. void    DitherTo12(void);
  120. UWORD    AddColour(struct RGB *);
  121.  
  122. /* modules that want to use the Get/PutValue macros should include this
  123.    next macro to externally reference the picture storage array */
  124. #define EXTERNBITPLANE extern struct RGB **BitPlane
  125.  
  126. /* for use once colour palette has been reduced to 12 bits */
  127. #define GetValue(a, b) *((UWORD *)&BitPlane[b][a])
  128. #define PutValue(a, b, c) *((UWORD *)&BitPlane[b][a]) = c
  129.  
  130. /* Copyright 1990 by Christopher A. Wichura.
  131.    See file GIFMachine.doc for full description of rights.
  132. */
  133.  
  134. #include <workbench/startup.h>
  135.  
  136. struct GIFdescriptor gdesc;
  137.  
  138. struct RGB **BitPlane;
  139. struct RGB GlobalColourTable[256];
  140.  
  141. ULONG ImageNumber;
  142.  
  143. /* the current GIF file handle */
  144. struct FileHandle *GIFfh = NULL;
  145.  
  146. /* here we have some defines relating to our GADS call */
  147. #define ESC "\x9B"
  148. #define GIFMACH ESC "33;42mGIFMachine" ESC "32;40m"
  149.  
  150. #define ARG_TEMPLATE "GIFfiles/M/A,TO/K,ALL/S,NOBORDER/K/N,XCOMP/S,DITHER/S,XFLIP/s,YFLIP/s,DEEP/S,BUFSIZE/K/N"
  151. #define ARG_FILES  0
  152. #define ARG_TO     1
  153. #define ARG_ALL    2
  154. #define ARG_NOBORD 3
  155. #define ARG_XCOMP  4
  156. #define ARG_DITHER 5
  157. #define ARG_FLIPX  6
  158. #define ARG_FLIPY  7
  159. #define ARG_DEEP   8
  160. #define ARG_BUFSIZ 9
  161. #define ARG_sizeof 10
  162.  
  163. /* we will make the argument array global so that other modules can get at
  164.    the ARG_TO, ARG_ALL and ARG_XCOMP fields easily */
  165. struct RDArgs *ArgsPtr;
  166. char *ArgArray[ARG_sizeof];
  167. BOOL ArgToIsDir;
  168.  
  169. /* size of the read buffered i/o space */
  170. static ULONG BufSize = 2048;    /* default size is 2k */
  171.  
  172. int NoBorderLineThresh = 0;
  173.  
  174. /* some mem pointers used when we do dithering */
  175. BYTE *CurrentLineErr[3];
  176. BYTE *LastLineErr[3];
  177.  
  178. /* this flag says if we scaled the image */
  179. BOOL DidXComp;
  180.  
  181. /* we print this when the user hits the break key */
  182. char *AbortMsg = "*** User Interruption!\n";
  183.  
  184. void MyExit( result)
  185. ULONG result;
  186. {
  187.     if (GIFfh)
  188.         Close(GIFfh);
  189.  
  190.     FreeAll( (UWORD) 1 );
  191.     FreeAll( (UWORD) 0 );
  192.  
  193.     return(result);
  194. }
  195.  
  196.  
  197. APTR DosBase;
  198. FILE *out;
  199.  
  200. void main( argc, argv  )
  201. int argc;
  202. char *argv[];
  203. {
  204.     DosBase = (APTR) OpenLibrary( "dos.library", 0 );
  205.  
  206.     if (DosBase)
  207.     {
  208.         {
  209.             int f;
  210.             printf("%s %s to %s\n", argv[0], argv[1], argv[2] );
  211.     
  212.             out = fopen( argv[2], "w" );
  213.             beak( argv[1] );
  214.  
  215.             fclose( out );
  216.         }
  217.         CloseLibrary( DosBase );
  218.     }
  219.     else
  220.     {
  221.         printf("Could not open dos.library\n");
  222.     }
  223. }
  224.  
  225. /* here we have the routine that gets ready to do the conversion */
  226.  
  227. void beak( name )
  228. char *name;
  229. {
  230.     register int index;
  231.     /*char *basename;
  232.     char *ptr;*/
  233.     char sig[7];
  234.     int size;
  235.     int error;
  236.     int colours;
  237.     LONG cmdcode;
  238.     unsigned char rid;
  239.  
  240.     printf("name: %s\n", name );
  241.  
  242.     if (!(GIFfh = (struct FileHandle *) Open(name, MODE_OLDFILE))) {
  243.         printf("Error #%ld trying to open %s...\n", IoErr(), name);
  244.         goto LeaveConvert;
  245.     }
  246.  
  247.     sig[6] = NULL;
  248.  
  249.     if ((Read(GIFfh, sig, 6) != 6) || strncmp("GIF", sig, 3)) {
  250.         printf("%s is not a GIF file...\n", name);
  251.         printf("%s\n", sig );
  252.         goto LeaveConvert;
  253.     }
  254.  
  255.     if (Read(GIFfh, (char *)&gdesc, 7) != 7) {
  256.         printf("Error reading screen descriptor.\n");
  257.         goto LeaveConvert;
  258.     }
  259.  
  260.     FlipWord(&gdesc.gd_Width);
  261.     FlipWord(&gdesc.gd_Height);
  262.  
  263.     printf("Signature = \"%s\", Width = %ld, Height = %ld\n",
  264.         sig, gdesc.gd_Width, gdesc.gd_Height);
  265.  
  266.     DidXComp = 0;
  267.     colours = 1L << ((gdesc.gd_ColInfo & 7) + 1);
  268.  
  269.     if (!(gdesc.gd_ColInfo & 1L << 7)) {
  270.         printf("No global colour map supplied, using internal.\n");
  271.  
  272.         for (index = 0; index < colours; index++) {
  273.             GlobalColourTable[index].rgb_Red   =
  274.             GlobalColourTable[index].rgb_Green =
  275.             GlobalColourTable[index].rgb_Blue  = index;
  276.         }
  277.     } else {
  278.         printf("Global colour map contains %ld entries.\n", colours);
  279.  
  280.         for (index = 0; index < colours; index++) {
  281.             if (Read(GIFfh, &GlobalColourTable[index], 3) != 3) {
  282.                 printf("Error reading global colour #%ld.\n",
  283.                     index);
  284.                 goto LeaveConvert;
  285.             }
  286.         }
  287.     }
  288.  
  289.     size = ((gdesc.gd_Width + 7) / 8) + 1;
  290.     size += (size + 127) >> 7;
  291.  
  292.     size = (gdesc.gd_Width + 1) * sizeof(struct RGB);
  293.  
  294.  
  295.     ImageNumber = 1;
  296.  
  297.     /* at this point we start looking for images, extensions or the gif
  298.        terminator.  we call the appropriate routine as we find each. */
  299.  
  300.     for (error = FALSE; error == FALSE;) {
  301.         if ( Read( GIFfh, &rid, 1) == -1) {
  302.             printf("...I/O error reading GIF file.\n");
  303.             goto LeaveConvert;
  304.         }
  305.         cmdcode=rid;
  306.  
  307.         switch(cmdcode) {
  308.             case GIF_IMAGE:
  309.                 error = DoImage( (APTR) GIFfh);
  310.                 break;
  311.  
  312.             case GIF_EXTENSION:
  313.                 error = DoExtension( (APTR) GIFfh);
  314.                 break;
  315.  
  316.             case GIF_TERMINATOR:
  317.                 break;
  318.  
  319.             default:
  320.                 printf("...Unknown directive #%ld encountered.\n",
  321.                     cmdcode);
  322.                 error = TRUE;
  323.         }
  324.     }
  325.  
  326. LeaveConvert:
  327.     if (GIFfh) {
  328.         Close(GIFfh);
  329.         GIFfh = NULL;
  330.     }
  331. }
  332.  
  333. struct MinList Mem[2];
  334. UWORD CurrentMem;
  335.  
  336. char *MyAlloc(size)
  337. ULONG size;
  338. {
  339.     register struct MyMem *theMemory;
  340.     register ULONG newsize;
  341.  
  342.     newsize = size + sizeof(struct MyMem);
  343.  
  344.     if (!(theMemory = (struct MyMem *)AllocMem(newsize, MEMF_PUBLIC|MEMF_CLEAR)))
  345.         return NULL;
  346.  
  347.     AddTail((struct List *)&Mem[CurrentMem], (struct Node *)&theMemory->mm_Node);
  348.     theMemory->mm_Size = newsize;
  349.  
  350.     return (char *)theMemory + sizeof(struct MyMem);
  351. }
  352.  
  353. void MyFree(MemPtr)
  354. char *MemPtr;
  355. {
  356.     register struct MyMem *theMemory;
  357.  
  358.     theMemory = (struct MyMem *)(MemPtr - sizeof(struct MyMem));
  359.  
  360.     Remove((struct Node *)&theMemory->mm_Node);
  361.     FreeMem((char *)theMemory, theMemory->mm_Size);
  362. }
  363.  
  364. void FreeAll(memlist)
  365. UWORD memlist;
  366. {
  367.     register struct MyMem *theMemory;
  368.  
  369.     while (theMemory = (struct MyMem *)RemTail((struct List *)&Mem[memlist]))
  370.         FreeMem((char *)theMemory, theMemory->mm_Size);
  371. }
  372.  
  373. struct MinList CommentList;
  374. static UBYTE buf[256];
  375.  
  376. BOOL DoExtension(fh)
  377. APTR fh;
  378. {
  379.     register LONG size;
  380.     register LONG cmdcode;
  381.     register char *Comment;
  382.     register char *OldComment;
  383.     register int CommentLength;
  384.     register int OldCommentLength;
  385.     register struct CommentNode *cn;
  386.     unsigned char rid;
  387.  
  388.     if (Read( fh, &rid, 1) == -1) {
  389.         printf("...I/O error reading extension block function code\n");
  390.         return TRUE;
  391.     }
  392.     cmdcode=rid;
  393.  
  394.     switch(cmdcode) {
  395.         case GIF_COMMENT_EXT:
  396.             printf("...Comment extension encountered.  Contents will be stored in an ANNO chunk.\n");
  397.  
  398.             if (!(cn = (struct CommentNode *)MyAlloc(sizeof(struct CommentNode)))) {
  399.                 printf("......Out of memory allocating comment block.\n");
  400.                 return TRUE;
  401.             }
  402.  
  403.             Comment = NULL;
  404.             CommentLength = 0;
  405.  
  406.             for (;;) {
  407.                 if ((size = fgetc(fh)) == -1) {
  408.                     printf("......I/O Error reading comment block.\n");
  409.                     return TRUE;
  410.                 }
  411.  
  412.                 if (size) {
  413.                     if (fread(fh, buf, 1, size) != size) {
  414.                         printf("......I/O Error reading comment block.\n");
  415.                         return TRUE;
  416.                     }
  417.  
  418.                     OldComment = Comment;
  419.                     OldCommentLength = CommentLength;
  420.                     CommentLength += size;
  421.  
  422.                     if (!(Comment = MyAlloc(CommentLength))) {
  423.                         printf("......Out of memory allocating comment block.\n");
  424.                         return TRUE;
  425.                     }
  426.  
  427.                     if (OldCommentLength) {
  428.                         CopyMem(OldComment, Comment, OldCommentLength);
  429.                         MyFree(OldComment);
  430.                     }
  431.  
  432.                     CopyMem(buf, &Comment[OldCommentLength], size);
  433.                 } else {    /* end of comment so store it */
  434.                     cn->cn_Comment = Comment;
  435.                     cn->cn_CommentLength = CommentLength;
  436.                     AddTail((struct List *)&CommentList, (struct Node *)cn);
  437.                     return FALSE;
  438.                 }
  439.             }
  440.             break;
  441.  
  442.         default:
  443.             printf("...Extension block function code #%ld not know, skipping.\n",
  444.              cmdcode);
  445.  
  446.             /* we must skip over any data for the extension block */
  447.             for (;;) {
  448.                 if ((size = fgetc(fh)) == -1) {
  449.                     printf("...I/O Error skipping unknown extension block.\n");
  450.                     return TRUE;
  451.                 }
  452.  
  453.                 if (size == 0)
  454.                     return FALSE;
  455.  
  456.                 if (fread(fh, buf, 1, size) != size) {
  457.                     printf("...I/O Error skipping unknown extension block.\n");
  458.                     return TRUE;
  459.                 }
  460.             }
  461.             break;
  462.     }
  463. }
  464.  
  465. /* this will convert a word from LSB/MSB to MSB/LSB */
  466. void FlipWord(word)
  467. UWORD *word;
  468. {
  469.     register UBYTE swap1;
  470.     register UBYTE swap2;
  471.  
  472.     swap1 = *word & 0xFF;
  473.     swap2 = (*word & 0xFF00) >> 8;
  474.     *word = swap1 << 8 | swap2;
  475. }
  476.  
  477. /*struct GIFdescriptor gdesc;*/
  478.  
  479. static struct ImageDesc idesc;
  480. /*struct RGB GlobalColourTable[256];*/
  481. static struct RGB LocalColourTable[256];
  482. /*ULONG ImageNumber;*/
  483.  
  484. extern char *AbortMsg;
  485.  
  486. static UWORD Xpos, Ypos;
  487. static BOOL interleave;
  488.  
  489. static UBYTE LeaveStep[5]  = {1, 8, 8, 4, 2};
  490. static UBYTE LeaveFirst[5] = {0, 0, 4, 2, 1};
  491.  
  492. /* some variables used by the decompressor */
  493. UWORD ReadError;
  494. UBYTE CodeSize;
  495. UWORD EOFCode;
  496. UBYTE ReadMask;
  497. UWORD    CompDataPointer;
  498. UWORD CompDataCount;
  499. UBYTE CompData[256];
  500.  
  501. /* tables used by the decompressor */
  502. static UWORD Prefix[4096];
  503. static UBYTE Suffix[4096];
  504. static UBYTE OutCode[1025];
  505.  
  506. APTR    dagiffh;
  507. UWORD Code;
  508. APTR date;
  509.  
  510. BOOL DoImage(fh)
  511. APTR fh;
  512. {
  513.     register int index;
  514.     register int colours;
  515.  
  516.     date= (APTR) &CompData[0];
  517.     dagiffh=fh;
  518.  
  519.     printf("...Image #%ld encountered.\n", ImageNumber++);
  520.  
  521.     if (Read(fh, (char *)&idesc, 9) != 9) {
  522.         printf("......Error reading image descriptor.\n");
  523.         return TRUE;
  524.     }
  525.  
  526.     FlipWord(&idesc.id_Left);
  527.     FlipWord(&idesc.id_Top);
  528.     FlipWord(&idesc.id_Width);
  529.     FlipWord(&idesc.id_Height);
  530.  
  531.     interleave = idesc.id_Info & 1L << 6;
  532.     if (interleave)
  533.         interleave = 1;
  534.  
  535.     printf("......Xpos from %ld to %ld, Ypos from %ld to %ld, %sinterlaced.\n",
  536.         idesc.id_Left, idesc.id_Left + idesc.id_Width - 1,
  537.         idesc.id_Top, idesc.id_Top + idesc.id_Height - 1,
  538.         interleave ? "" : "not ");
  539.  
  540.     if (idesc.id_Info & 1L << 7) {
  541.         colours = 1L << ((idesc.id_Info & 7) + 1);
  542.         printf("......Local colour map contains %ld entries.\n", colours);
  543.  
  544.         for (index = 0; index < colours; index++) {
  545.             if (Read(fh, &LocalColourTable[index], 3) != 3) {
  546.                 printf("......Error reading local colour #%ld.\n",
  547.                     index);
  548.                 return TRUE;
  549.             }
  550.         }
  551.     } else {
  552.         colours = 1L << ((gdesc.gd_ColInfo & 7) + 1);
  553.         CopyMem((char *)GlobalColourTable, (char *)LocalColourTable,
  554.             sizeof(LocalColourTable));
  555.     }
  556.  
  557.     Xpos = Ypos = 0;
  558.  
  559.     /* now we are ready to read the image in so do it! */
  560.  
  561.     {
  562.         int MaxCode, ClearCode, CurCode,
  563.             OldCode, InCode, FreeCode;
  564.         int OutCount;
  565.         int FirstFree;
  566.         UBYTE InitCodeSize, FinChar, BitMask;
  567.  
  568.         printf("......Decompressing line number %5ld", Ypos);
  569.  
  570.         /* get the codesize and do general setup for decompression */
  571.         if (Read(fh, &CodeSize, 1) == -1) {
  572.             printf("\n......I/O Error during decompression.\n");
  573.             return TRUE;
  574.         }
  575.  
  576.         ClearCode = 1L << CodeSize;
  577.         EOFCode = ClearCode + 1;
  578.         FreeCode = FirstFree = ClearCode + 2;
  579.  
  580.         CodeSize++;    /* per GIF spec */
  581.         InitCodeSize = CodeSize;
  582.         MaxCode = 1L << CodeSize;
  583.         ReadError = ReadMask = OutCount = 0;
  584.         CompDataPointer = CompDataCount = 0;
  585.  
  586.         BitMask = colours - 1;
  587.  
  588.         Code = ReadCode(fh);
  589. /*        ReadCodex();*/
  590.         while( Code != EOFCode ) {
  591.             if (ReadError)
  592.                 return TRUE;
  593.  
  594.             if (Code == ClearCode) {
  595.                 CodeSize = InitCodeSize;
  596.                 MaxCode = 1L << CodeSize;
  597.                 FreeCode = FirstFree;
  598.                 FinChar = CurCode = OldCode = Code = ReadCode(fh);
  599. /*                ReadCodex();*/
  600.                 FinChar = CurCode = OldCode = Code;
  601.                 AddPixel(FinChar);
  602.             } else {
  603.                 CurCode = InCode = Code;
  604.  
  605.                 if (CurCode >= FreeCode) {
  606.                     CurCode = OldCode;
  607.                     OutCode[OutCount++] = FinChar;
  608.                 }
  609.  
  610.                 while (CurCode > BitMask) {
  611.                     if (OutCount > 1024) {
  612.                         printf("\n......Corrupt GIF file (OutCount)\n");
  613.                         return TRUE;
  614.                     }
  615.  
  616.                     OutCode[OutCount++] = Suffix[CurCode];
  617.                     CurCode = Prefix[CurCode];
  618.                 }
  619.  
  620.                 FinChar = CurCode;
  621.                 AddPixel(FinChar);
  622.  
  623.                 for (index = OutCount - 1; index >= 0; index--)
  624.                     AddPixel(OutCode[index]);
  625.                 OutCount = 0;
  626.  
  627.                 Prefix[FreeCode] = OldCode;
  628.                 Suffix[FreeCode] = FinChar;
  629.                 OldCode = InCode;
  630.  
  631.                 if (++FreeCode >= MaxCode) {
  632.                     if (CodeSize < 12) {
  633.                         CodeSize++;
  634.                         MaxCode <<= 1;
  635.                     }
  636.                 }
  637.             }
  638.  
  639.             Code = ReadCode(fh);
  640. /*            ReadCodex();*/
  641.         }
  642.     }
  643.  
  644.     if ((Code = fgetc(fh)) == -1)
  645.         return TRUE;
  646.  
  647.     /* done decompressing.  Erase decompressing message and exit */
  648.     printf("\x9B22D\x9BKed.\n");
  649.  
  650.     if (Code != 0) {
  651.         printf("......Warning:  Unaligned packet.\n");
  652.         ungetc(fh, Code);
  653.     }
  654.  
  655.     return FALSE;
  656. }
  657.  
  658. int ReadCode(fh)
  659. APTR fh;
  660. {
  661.     register int temp;
  662.     register int DstMasked;
  663.     register int DstMask;
  664.     register LONG size;
  665.     unsigned char rid;
  666.  
  667.     temp = 0;
  668.     DstMasked = 1L << CodeSize;
  669.     for (DstMask = 1; DstMask != DstMasked; DstMask <<= 1) {
  670.         if (!ReadMask) {
  671.             if (CompDataPointer == CompDataCount) {
  672.                 if (Read( fh, &rid, 1) == -1) {
  673.                     printf("\n......I/O Error during decompression.\n");
  674.                     ReadError = 1;
  675.                     return EOFCode;
  676.                 }
  677.                 size=rid;
  678.  
  679.                 if (Read(fh, (char *)CompData, size) != size) {
  680.                     printf("\n......I/O Error during decompression.\n");
  681.                     ReadError = 1;
  682.                     return EOFCode;
  683.                 }
  684.  
  685.                 CompDataCount = size;
  686.                 CompDataPointer = 0;
  687.             }
  688.  
  689.             ReadMask = 1;
  690.             ByteBuf = CompData[CompDataPointer++];
  691.         }
  692.  
  693.         if (ByteBuf & ReadMask)
  694.             temp |= DstMask;
  695.  
  696.         ReadMask <<= 1;
  697.     }
  698.  
  699.     return temp;
  700. }
  701.  
  702. void AddPixel(index)
  703. UBYTE index;
  704. {
  705.     register UWORD tile;
  706.     UWORD row;
  707.     UWORD byte;
  708.  
  709.     register UWORD manip2;
  710.     register UWORD manip;
  711.     register UBYTE schreib;
  712.  
  713. /*    SetAPen( rastport, index );*/
  714. /*    WritePixel( rastport, XStore, YStore+20 );*/
  715.  
  716.     fprintf( out, "%c", index );
  717.  
  718. /*    tile = (Ypos/16)*20 + Xpos/16;
  719.  
  720.     row = Ypos & 15;
  721.     byte = (Xpos & 8)/8;
  722.  
  723.     {
  724.         manip = 1 << ( 7 - ( Xpos & 7 ) );
  725.         manip2 = 255 ^ manip;
  726.     
  727.         if( ( index & 1 ) != 0 )
  728.         {
  729.             tiles[ tile ][ 0 ][ row ][ byte ] |= manip;
  730.         }
  731.         else
  732.         {
  733.             tiles[ tile ][ 0 ][ row ][ byte ] &= manip2;
  734.         }
  735.  
  736.         if( ( index & 2 ) != 0 )
  737.         {
  738.             tiles[ tile ][ 1 ][ row ][ byte ] |= manip;
  739.         }
  740.         else
  741.         {
  742.             tiles[ tile ][ 1 ][ row ][ byte ] &= manip2;
  743.         }
  744.  
  745.         if( ( index & 4 ) != 0 )
  746.         {
  747.             tiles[ tile ][ 2 ][ row ][ byte ] |= manip;
  748.         }
  749.         else
  750.         {
  751.             tiles[ tile ][ 2 ][ row ][ byte ] &= manip2;
  752.         }
  753.  
  754.         if( ( index & 8 ) != 0 )
  755.         {
  756.             tiles[ tile ][ 3 ][ row ][ byte ] |= manip;
  757.         }
  758.         else
  759.         {
  760.             tiles[ tile ][ 3 ][ row ][ byte ] &= manip2;
  761.         }
  762.  
  763.         if( ( index & 16 ) != 0 )
  764.         {
  765.             tiles[ tile ][ 4 ][ row ][ byte ] |= manip;
  766.         }
  767.         else
  768.         {
  769.             tiles[ tile ][ 4 ][ row ][ byte ] &= manip2;
  770.         }
  771.  
  772.         if( ( index & 32 ) != 0 )
  773.         {
  774.             tiles[ tile ][ 5 ][ row ][ byte ] |= manip;
  775.         }
  776.         else
  777.         {
  778.             tiles[ tile ][ 5 ][ row ][ byte ] &= manip2;
  779.         }
  780.  
  781.         if( ( index & 64 ) != 0 )
  782.         {
  783.             tiles[ tile ][ 6 ][ row ][ byte ] |= manip;
  784.         }
  785.         else
  786.         {
  787.             tiles[ tile ][ 6 ][ row ][ byte ] &= manip2;
  788.         }
  789.  
  790.         if( ( index & 128 ) != 0 )
  791.         {
  792.             tiles[ tile ][ 7 ][ row ][ byte ] |= manip;
  793.         }
  794.         else
  795.         {
  796.             tiles[ tile ][ 7 ][ row ][ byte ] &= manip2;
  797.         }
  798.  
  799.     }
  800. */
  801.     if (++Xpos == idesc.id_Width) {
  802.         Xpos = 0;
  803.         Ypos += LeaveStep[interleave];
  804.         if (Ypos >= idesc.id_Height)
  805.             Ypos = LeaveFirst[++interleave];
  806.  
  807.         printf("\x9B5D%5ld", Ypos + idesc.id_Top);
  808.     }
  809. }
  810.